STEPPER MOTOR INTERFACING WITH PIC
A stepper motor is a brushless, synchronous electric motor that converts digital pulses into mechanical shaft rotation.
Synopsis

A stepper motor is a brushless, synchronous electric motor that converts digital pulses into mechanical shaft rotation. Every revolution of the stepper motor is divided into a discrete number of steps, and the motor must be sent a separate pulse for each step.

Programmable Counter Array (PCA) of the microcontroller PIC18F4550 uses to generate the control signals to the Power Interface. The Power Interface allows the microcontroller PIC18F4550 to drive enough current into coils of a stepper motor. There are two advantages to using PCA. First of all, PCA provides greater accuracy than toggling pins in software because the toggle occurs before the interrupt request is serviced. Thus, interrupt response time does not affect the accuracy of the output. Secondly the PIC18F4550 microcontroller CPU is left free for application task execution while the PCA drives stepper motors.

There are two major types of stepper motors: Permanent magnet stepper motors (unipolar stepper motors and bipolar stepper motors) and variable reluctance stepper motors (hybrid stepper motors).

Description

Stepper motors are used in a wide variety of applications. They are prevalent in consumer office equipment such as printers, plotters, copiers, and Scanners. Stepper motors are also used in automotive applications for electronic throttle control, dashboard indicators, and climate control systems. Stepper motors are also found in industrial equipment such as robotics, electronic component handlers, testers, dispensers, and other manufacturing equipment. It is often controlled using special function ICs that provide limited control functionality.

Motor:

There are several types of stepper motors, these cannot be driven in the same way. Unipolar Stepper Motor Unipolar stepper motors are characterized by their center-tapped windings.

Unipolar stepper motor

In the unipolar stepper motor, it works with one winding with a center tap per phase, each section of the phase winding is turned on for each of the magnetic field direction. Since unipolar stepper motors are quite easy to operate. Unlike dc motors, which spin round freely when power is applied, stepper motors require that their power supply be continuously pulsed in specific patterns. For each pulse, the stepper motor moves around one ‘step’, often 7.5 degrees (giving 48 steps in a full revolution).

As the stepper motor operates at 12V, the standard transistor circuit is required to switch each coil. As the coils create a back emf when switched off, a suppression diode on each coil is also required. The table below show the four different steps required to make the motor turn.

Coil 2 is always the opposite (or logical NOT) of coil 1. The same applies for coils 3 and 4. It is therefore possible to cut down the number of microcontroller PIC18F4550 pins required to just two by the use of two additional NOT gates.



Bipolar Stepper Motor

Bipolar stepper motors are designed with separate coils. The bipolar stepper motor has two coils that must be controlled so that the current flows in different directions through the coils in a certain order. The changing magnetic fields that these coils create cause the rotor of the motor to move around in steps.



Variable Reluctance stepper motor (also called hybrid motors) are characterized by one common lead.


The ULN2003A is a current driver IC. It is used to drive the current of the stepper motor as it requires more than 60mA of current. It is an array of Darlington pairs. It consists of seven pairs of Darlington arrays with common emitter. The IC consists of 16 pins in which 7 are input pins, 7 are output pins and remaining are VCC and Ground. The first four input pins are connected to the PIC18F4550 microcontroller. In the same way, four output pins are connected to the stepper motor.

Stepper motor has 6 pins. In these six pins, 2 pins are connected to the supply of 12V and the remaining is connected to the output of the stepper motor. Stepper rotates at a given step angle. Each step in rotation is a fraction of full cycle. This depends on the mechanical parts and the driving method.

Similar to all the motors, stepper motors will have stator and rotor. Rotor has permanent magnet and stator has coil. The basic stepper motor has 4 coils with 90 degrees rotation step. These four coils are activated in the cyclic order.

Step Angle

Step angle of the stepper motor is defined as the angle traversed by the motor in one step. To calculate step angle,simply divide 360 by number of steps a motor takes to complete one revolution. As we have seen that in half mode, the number of steps taken by the motor to complete one revolution gets doubled, so step angle reduces to half.

As in above examples, Stepper Motor rotating in full mode takes 4 steps to complete a revolution, So step angle can be calculated as...

Step Angle ø = 360° / 4 = 90°

and in case of half mode step angle gets half so 45°.

So this way we can calculate step angle for any stepper motor. Usually step angle is given in the spec sheet of the stepper motor you are using. Knowing stepper motor's step angle helps you calibrate the rotation of motor also to helps you move the motor to correct angular position.

Driving Unipolar Stepper

Motors:

Mainly there are 3 types of stepping modes in Unipolar stepper motors

• Full step (One Phase on Mode, Two Phases on Mode)

• Half step

• Micro step

Full Step

In full step operation, each step has a movement of 1.8 degrees and hence it takes 200 steps to complete a full revolution. This is made possible by energising either single of stator winding or two phases. Since the two phases are energised at the same time in the dual phase operation, torque and speed are greater in this kind of operation while the single phase operation requires lower amount of power from the driver circuit.

There are two types of full step mode:

• One step mode / wave step

• Dual phase mode

In one step mode/ wave step, the motor is operated with only one phase energized at a time. This mode of operation requires small amount of power.



In one phase mode, each successive coil is energized in turn. One phase mode produces smooth rotations and the lowest power consumption of the three modes. Steps are applied in order from one to four. After step four, the sequence is repeated from step one. Applying steps from one to four makes the motor run clockwise, reversing the order of step from four to one will make the motor run counter-clockwise.


Two Phases on Mode

(Alternate Full step Mode)



In two phase mode, successive pairs of adjacent coils are energized in turn, motion is not as smooth as in one phase mode, power consumption is more important but it produces greater torque. As in one phase mode, applying the steps in order makes the stepper motor run clockwise and reversing order makes it turn counter-clockwise.


Half Step Mode


The half step sequence is a mix of one phase on and two phases on sequences. The main advantage of this mode is to increase by two the nominal number of steps of your stepper motor. By example, a unipolar stepper motor of 24 steps of 15 degrees each "becomes", when we use half step mode, a stepper motor of 48 steps of 7.5 degrees.




Micro step

In micro step mode, it divides the motor steps up to 256 times which improves the low speed smoothness and low speed resonance effects. But in this mode, motor produces less torque compared to other mode. In micro step operation, the basic angle is divided into minute values even up to 256 times. Microstep operation is preferred where increased smoothness of rotation is required.

Driving Bipolar Stepper

Motors:

Bi-polar stepper motors has 2 different coils. The step sequence for Bipolar stepper motor is same as that of unipolar stepper motors. The driving circuit for this require an H-Bridge as it allows the polarity of the power applied to be controlled independently.


Advantages

• Excellent low speed torque (Can drive many loads without gearing).

• Excellent repeatability (Returns to the same location accurately).

• Overload safe ( Motor cannot be damaged by mechanical overload).

Applications

• Blood-oxygenating pumps

• CT scanners

• Air control valves

• Head light adjustment motors

Proteus design for Unipolar Stepper Motor interfacing with PIC


Proteus design for Bipolar Stepper Motor interfacing with PIC


Orcad design for Unipolar Stepper Motor interfacing with PIC


Proteus design for Bipolar Stepper Motor interfacing with PIC


Full Drive Unipolar Stepper Motor interfacing with PIC

/*  Name     : unipolar_FS.c
 *  Purpose  : Source code for Unipolar Fullstep Stepper Motor with PIC18F4550.
 *  Author   : Gemicates
 *  Date     : 2017-06-29
 *  Website  : www.gemicates.org
 *  Revision : None
 */


/**** Full step drive Mode****/
#include <htc.h>                       // Header file for PIC18F4550 series
#define _XTAL_FREQ 12000000            // 12MHz Crystal Frequency for PIC18F4550

void delay_ms();                       // delay declaration
unsigned int i;

void main()                            // main fuction
{
   PORTD = 0;
   TRISD = 0;                          // Configure PORTD as output

   while(1) {                          // loop executed infinite times
      for(i=0;i<49;i++)
        {
          PORTD=0x09;                  // 1001
        __delay_ms(60);                // delay
        }
      for(i=0;i<49;i++)
        {
          PORTD=0x0C;                  //1100
        __delay_ms(60);
        }
      for(i=0;i<49;i++)
        {
          PORTD=0x06;                  //0110
        __delay_ms(60);
        }
      for(i=0;i<49;i++)
        {
          PORTD=0x03;                  //0011
        __delay_ms(60);
        }
    }
}
Half Drive Unipolar Stepper Motor interfacing with PIC

/*  Name     : unipolar_HS.c
 *  Purpose  : Source code for Unipolar Halfstep Stepper Motor with PIC18F4550.
 *  Author   : Gemicates
 *  Date     : 2017-06-29
 *  Website  : www.gemicates.org
 *  Revision : None
 */


/**** Half Drive Stepping Mode ****/
#include <htc.h>                      // Header file for PIC18F4550 series                        
#define _XTAL_FREQ 12000000           // 12MHz Crystal Frequency for PIC18F4550
void delay_ms();                      // delay declaration
unsigned int i;

void main()                           // main fuction
{
  PORTD = 0;
  TRISD = 0;                          // Configure PORTD as output

  while(1) {                          // loop executed infinite times

     for(i=0;i<49;i++)
      {
       PORTD=0x08;                    // 1000
      __delay_ms(60);                 // delay
      }
     for(i=0;i<49;i++)
      {
       PORTD=0x0C;                    // 1100
     __delay_ms(60);
      }
    for(i=0;i<49;i++)
      {
       PORTD=0x04;                    // 0100
     __delay_ms(60);
      }
    for(i=0;i<49;i++)
     {
       PORTD=0x06;                    // 0110
     __delay_ms(60);
     }
    for(i=0;i<49;i++)
     {
       PORTD=0x02;                    // 0010
     __delay_ms(60);
     }
    for(i=0;i<49;i++)
     {
       PORTD=0x03;                    // 0011
     __delay_ms(60);
     }
    for(i=0;i<49;i++)
     {
       PORTD=0x01;                    // 0001
     __delay_ms(60);
     }
   for(i=0;i<49;i++)
     {
       PORTD=0x09;                    // 1001
     __delay_ms(60);
     }

   }
}
Wave Drive Unipolar Stepper Motor interfacing with PIC

/*  Name     : unipolar_FS.c
 *  Purpose  : Source code for Unipolar wave drive Stepper Motor with PIC18F4550.
 *  Author   : Gemicates
 *  Date     : 2017-06-29
 *  Website  : www.gemicates.org
 *  Revision : None
 */


/**** Wave Drive Stepping Mode****/
#include <htc.h>                       // Header file for PIC18F4550 series 
#define _XTAL_FREQ 12000000            // 12MHz Crystal Frequency for PIC18F4550
void delay_ms();                       // delay declaration
unsigned int i;

void main()                            // main fuction
{
PORTD = 0;
TRISD = 0;                             // Configure PORTD as output

while(1) {                             // loop executed infinite times
    for(i=0;i<49;i++)
     {
       PORTD=0x08;                     // 1000
     __delay_ms(60);                   // delay
     }
   for(i=0;i<49;i++)
     {
       PORTD=0x04;                     //0100
     __delay_ms(60);
     }
   for(i=0;i<49;i++)
     {
       PORTD=0x02;                     //0010
     __delay_ms(60);
     }
   for(i=0;i<49;i++)
     {
       PORTD=0x01;                     //0001
     __delay_ms(60);
     }
  }
}
Bipolar Stepper Motor interfacing with PIC

/*  Name     : bipolar.c
 *  Purpose  : Source code for Bipolar Stepper Motor with PIC18F4550.
 *  Author   : Gemicates
 *  Date     : 2017-06-28
 *  Website  : www.gemicates.org
 *  Revision : None
 */

/**** Program to interface Bipolar Stepper Motor with PIC18F4550 ****/
#include <htc.h>                       // Header file for PIC18F4550 series
#define _XTAL_FREQ 12000000            // 12MHz Crystal Frequency for PIC18F4550

void delay_ms();                       // delay declaration
unsigned int i;

void main()                            // main fuction
    {
    TRISD = 0b0000000;                 // PORT D as output port
    PORTD = 0b0000000;
    while(1) {                         // loop executed infinite times
    for(i=0;i<49;i++)
        {
          PORTD= 0b00000001;           // 0001
        __delay_us(60);                // delay 
        }
    for(i=0;i<49;i++)
        {
          PORTD= 0b00000100;           //0100
        __delay_ms(60);
        }
    for(i=0;i<49;i++)
     
        {
          PORTD = 0b00000010;          //0010
        __delay_ms(60);
        }
    for(i=0;i<49;i++)
        
        {
          PORTD = 0b00001000;          //1000
        __delay_ms(60);
        }
    }
    
 }  

Error message here!

Show Error message here!


Forgot your password?

Error message here!

Send OTP

Error message here!

Show Error message here!


Lost your password? Please enter your email address. You will receive a password you Need.

Send Error message here!


Back to log-in

Close